<?php
/**
 * Created by PhpStorm.
 * User: asdf
 * Date: 2021/9/18
 * Time: 23:48
 */

namespace core\lib;


use function core\p;

class route{

    public static $instance;
    public $ctl;
    public $action;
    public static $uri = null;
    public static $patharr = [];


    /**
     * 隐藏index
     * 获取参数
     * 返回控制器和方法
     */
    public function __construct($qurey_src)
    {
        self::$uri = $qurey_src;
        $this->loader();
        $this->getControler();
        $this->getAction();


    }

    private function loader(){

        if (isset(self::$uri)&&self::$uri !="/" || self::$uri == ""){
            self::$patharr = explode('/',trim(self::$uri,'/'));
        }else{
            $this->ctl='index';
            $this->action = 'index';
        }
    }

    //控制器
    private function getControler(){
        //控制器
        if (isset(self::$patharr[0])){
            $this->ctl = self::$patharr[0];
        }else{
            $this->ctl = 'index';
        }
    }

    private function getAction(){
        //操作
        if (isset(self::$patharr[1])){
            $this->action = self::$patharr[1];
        }else{
            $this->action = 'index';
        }
    }



    public static function Newinstance($qurey_src){
        if(!self::$instance instanceof self){
            self::$instance = new self($qurey_src);
        }
        return self::$instance;
    }







}